import React from 'react';
import dayjs from 'dayjs';
import { Button } from '@arco-design/web-react';
import { MessageType } from '@arco-design/web-react/es/Message';

function getColumns(
  callback: (record, type) => Promise<MessageType>
) {
  return [
    {
      title: 'Id',
      dataIndex: 'id',
    },
    {
      title: '用户名',
      dataIndex: 'username',
    },
    {
      title: '积分数',
      dataIndex: 'points',
    },
    {
      title: '创建时间',
      dataIndex: 'created_at',
      render: (value) => dayjs(value).format('YYYY-MM-DD HH:mm:ss')
    },
    {
      title: '更新时间',
      dataIndex: 'updated_at',
      render: (value) => dayjs(value).format('YYYY-MM-DD HH:mm:ss')
    },
    {
      title: '邮箱',
      dataIndex: 'emails',
      render: (_, record) => (
        <Button
          type="text"
          size="small"
          onClick={() => callback(record, 'view_emails')}
        >
          查看邮件
        </Button>
      )
    },
    {
      title: '订阅',
      dataIndex: 'subs',
      render: (_, record) => (
        <Button
          type="text"
          size="small"
          onClick={() => callback(record, 'view_subs')}
        >
          查看订阅
        </Button>
      )
    },
    {
      title: '积分日志',
      dataIndex: 'points_log',
      render: (_, record) => (
        <Button
          type="text"
          size="small"
          onClick={() => callback(record, 'view_logs')}
        >
          查看日志
        </Button>
      )
    },
    {
      title: '操作',
      dataIndex: 'operate',
      render: (_, record) => (
        <div>
          <Button
            type="text"
            size="small"
            onClick={() => callback(record, 'view')}
          >
            查看
          </Button>
          <Button
            type="text"
            size="small"
            onClick={() => callback(record, 'edit')}
          >
            编辑
          </Button>
          <Button
            type="text"
            size="small"
            onClick={() => callback(record, 'delete')}
            disabled={record.is_admin}
          >
            删除
          </Button>
        </div>
      ),
    },
  ];
}
export default getColumns;